<?php 
$sql =	"SELECT
			  c.page_id,
			  d.title,
			  d.description,
			  d.meta_key,
			  d.meta_description	
		  FROM
			  pages AS c,
			  page_description AS d
		  WHERE
		  
			  c.page_id = d.page_id
			  AND
			  d.lang_id = '".$_SESSION['lang_id']."'
			  AND
			  c.sef_url = 'login' 
			  AND c.published
		  ";
$result = query($sql);
$row = mysql_fetch_object($result);


head(sth($row->title),sth($row->meta_description));

?>


		
        
        
        <div id="content">
			
			<div class="left narrow">
				
				<div id="bigtab1" class="biglogin redcolor">
					<?=__SIGN_IN?>
				</div>
				
				<div id="bigtab2" class="bigregister">
					<?=__SIGN_UP?>
				</div>
				
			</div>
			
			<div class="right wide">
				
				<div class="bigarrow">
				</div>
				
				<div class="bigdivs">
					<div id="bigdiv1">
						<div class="message red"></div>
                        
                        <form id="login-data" action="https://portal.olapark.pt/login_from_web.aspx" method="post" enctype="multipart/form-data">
                    
                        <input type="hidden" name="uName" value=""/>
                        <input type="hidden" name="uPass" value=""/>
                        <input type="hidden" name="uPersistent" value=""/>
                        
                        </form>
                        
                        
						<form id="login-form">
						<?=__Username?><br>
						<input id="login-user" name="username" type="text" value=""><br>
						<?=__Password?><br>
						<input id="login-pass" name="password" type="password" value=""><br>
						<br>
						<label>
						<input id="login-remember"  name="remember" type="checkbox" >
						
						<?=__Remember_me?></label><br><br>
						
						<a href="#" onclick="login(); return false;" class="button"><?=__Login?></a>
						
						<br><br>
						<a href="#"><?=__lost_password?></a>
						</form>
						
                      
					</div>
					
					<div id="bigdiv2">
						<div class="message red"></div>
						
						<form id="reg-form">
						<table width="100%">
							<tr>
								<td>
									<?=__Select_home_country?><br>
									<div class="select white">
                                    <select id="regform-country">
									  <option value="">-- <?=__SELECT?> --</option>
									 <?php
                                     $url = 'https://portal.olapark.pt/OlaParkUsersDataService.svc/GetCountriesList';
									 $json = file_get_contents($url);
									 
									 $jarr = json_c_decode($json);
									 $jarr = json_c_decode($jarr);
									 
									 
									 
									 foreach ($jarr as $key => $value)
									  {	
									  $value['Phone_Code'] = str_replace ('+','',$value['Phone_Code']);
									  $selected = '';	
									  if(strtolower ($value['ISO_Code2']) == $_SESSION['lang']){ $selected = 'selected'; $phone = $value['Phone_Code']; }
									  
				 					?>
                                    
                                    <option data-id="<?=$value['Phone_Code']?>" <?=$selected?> value="<?=$value['Id']?>"><?=$value['Country']?></option>
                                    <?php
				
						
					
									 }
									 
									 ?>
									</select></div>
								</td>
								<td>
									<?=__E_mail?><br>
									<input name="email" id="regform-email" type="text" value="">
								</td>
							</tr>
							<tr>
								<td>
									<?=__Mobile?><br>
									<input name="phone" id="regform-phone" type="text" value="<?=$phone?> ">
								</td>
								<td>
									<?=__Username?><br>
									<input name="username" id="regform-user" type="text" value="">
								</td>
							</tr>
							<tr>
								<td>
									<?=__First_Name?><br>
									<input name="name" id="regform-fname" type="text" value="">
								</td>
								<td>
									<?=__Last_Name?><br>
									<input name="lastname" id="regform-lname" type="text" value="">
								</td>
							</tr>
							<tr>
								<td>
									
                                    <?=__Password?><br>
									<input  id="regform-pass"  type="password" value="">
								</td>
								<td>
									<?=__Confirm_password?><br>
									<input id="regform-cpass" type="password" value="">
								</td>
							</tr>
						</table>
						
						<br><br>
						
						<label>
						<input id="regform-igree" type="checkbox" value="1">
						<?=__I_agree_to_the?> <a target="_blank" href="<?=HTML_BASE.$_SESSION['lang']?>/terms-of-use"><?=__Terms_and_Conditions?></a>
						</label>
						
						<br><br>
						<a class="button" href="#" onclick="Registration(); return false;"><?=__Register?></a>
                        
                        
						</form>
						

						
					</div>
				</div>
				
				
			</div>
			
		</div>
   <script type="text/javascript">
   
   			function print_r(o){
			return JSON.stringify(o,null,'\t').replace(/\n/g,'<br>').replace(/\t/g,'&nbsp;&nbsp;&nbsp;'); }	 
   
			var minUser = 6;
			var minPhone = 8;
			var minPass = 6;
			
			var url = 'https://portal.olapark.pt/OlaParkUsersDataService.svc/';
			var redirect = 'https://portal.olapark.pt/';
			function IsEmail(email) {
			  var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			  return regex.test(email);
			}
			
			
			
			function login()
				{
					
					$('#bigdiv1 input,select').removeClass('redborder');
					$('#bigdiv1 .message').slideUp();
					var error = ''
				
					if(!$('#login-user').val())
					{ 
						error +='<?=__err_user_empty?>!<br/>';
						$('#login-user').addClass('redborder');
					}	
					
					if(!$('#login-pass').val())
					{ 
						error +='<?=__err_pass_empty?>!<br/>';
						$('#login-pass').addClass('redborder');
					}					
					
					
					
					
					if(!error)
					{
						var remember = 0;
						if($('#login-remember :checked')) remember = 1;
						
						$('[name="uName"]').val(base64.encode($('#login-user').val()));
						$('[name="uPass"]').val(base64.encode($('#login-pass').val()));
						$('[name="uPersistent"]').val(remember);
						
						$('#login-data').submit();
						/*var logindata = {
									 uName:$('#login-user').val(),
									 uPass:$('#login-pass').val(), 
									 uPersistant: remember
									 
									 };
									 logindata = JSON.stringify(logindata);
									 logindata = JSON.stringify(logindata);
										
									   $.ajax({
											type: 'POST',
											url: url+'FastLogin',
											 dataType: 'json',
											 contentType: 'application/json',
											 data: logindata,
											
											
											success: function(msg){
												
												var cred = JSON.parse(msg.FastLoginResult); 
												
												if (cred.IsAuthenticated && cred.IsActivated) {
													window.location = redirect+'master.aspx';
												} else if (cred.IsAuthenticated && !cred.IsActivated) {
													window.location = redirect+'user_activation.aspx';
												} else {
													window.location = redirect+'errorpage.aspx';
												}
											},
											error: function(msg){
												alert('Err:'+ msg)
											}
										});*/
					}else{
						$('#bigdiv1 .message').html(error);
						$('#bigdiv1 .message').slideDown();	
					}
								 
				}
			
			
			var message = false;
			function avel(get,variable)
				{
					var funckt = '';
					if(get == 'phone') funckt = 'CheckUserMobileExist';
					if(get == 'user') funckt = 'CheckUserNameExist';
					if(get == 'email') funckt = 'CheckUserEmailExist';
					
					$.ajax({
										type: "GET",
										url: url+funckt+'?'+variable,
										data: '',
										async: false,
										success: function(msg){
											message =  false;
											if(msg.length == 4)
											{ 
											   message =  true;
											   
											}
											
											 
										},
										error: function(msg){
											alert('Err:'+ msg)
										}
									});
									
									
									return message;
					
				}
				
				
			
			function Registration()
			{
				
				
				
				
				$('#bigdiv2 input,select').removeClass('redborder');
				$('#bigdiv2 .message').slideUp();
				var error = ''
				if(!$('#regform-country').val())
				{ 
					error +='<?=__err_choise_country?>!<br/>';
					$('#regform-country').addClass('redborder');
				}
				
				if(!$('#regform-email').val())
				{ 
					error +='<?=__err_email_empty?>!<br/>';
					$('#regform-email').addClass('redborder');
				}else{
					
					if(!IsEmail($('#regform-email').val())){
						 error +='<?=__err_email_invalid?>!<br/>';
						 $('#regform-email').addClass('redborder');
					}else{
						
						if(avel('email','uEmail='+$('#regform-email').val()) )
						{
							error +='<?=__err_email_busy?>!<br/>'; 
							$('#regform-email').addClass('redborder');
						}
					}
				}
				
				if(!$('#regform-user').val())
				{ 
					error +='<?=__err_user_empty?>!<br/>';
					$('#regform-user').addClass('redborder');
				}else{
					if($('#regform-user').val().length < minUser)
					{
						error +='<?=__err_user_minimum?>'+minUser+' <?=__symbols?>!<br/>';
						$('#regform-user').addClass('redborder');
					}else{
						
						
						if(avel('user','uName='+$('#regform-user').val())  )
						{
							error +='<?=__err_user_busy?>!<br/>';
						    $('#regform-user').addClass('redborder');
						}
					}
				}
				
				
				
					if($('#regform-phone').val().length < minPhone)
					{
						error +='<?=__err_phone?> '+ minPhone+' <?=__symbols?>!<br/>';
						$('#regform-phone').addClass('redborder');
					}else{
						if(avel('phone','uMobile='+$('#regform-phone').val().substr(3,$('#regform-phone').val().length)+'&cCode='+$('option:selected', $('#regform-country')).attr('data-id') ) )
						{
							error +='<?=__err_phone_busy?>!<br/>';
						    $('#regform-phone').addClass('redborder');
						}
					}
					
					
					if(!$('#regform-fname').val())
					{
						error +='<?=__err_name?>!<br/>';
						$('#regform-fname').addClass('redborder');
					}
					
					if(!$('#regform-lname').val())
					{
						error +='<?=__err_lastname?>!<br/>';
						$('#regform-lname').addClass('redborder');
					}
					
					
					if($('#regform-pass').val().length < minPass)
					{
						error +='<?=__err_pass_min?> '+ minPass+' <?=__symbols?>!<br/>';
						$('#regform-pass').addClass('redborder');
					}
					
					
					if(!$('#regform-cpass').val())
					{
						error +='<?=__err_pass_conf?>!<br/>';
						$('#regform-cpass').addClass('redborder');
					}else{
						if($('#regform-cpass').val() != $('#regform-pass').val())
						{
							error +='<?=__err_pass_no_mach?> !<br/>';
							$('#regform-cpass').addClass('redborder');
						}
					}
				
				
				if(!$("#regform-igree").attr("checked"))
			    {
					error +='<?=__err_agree?> !<br/>';
				    $('#regform-igree').addClass('redborder');
				}
				
				
				
				if(!error)
				{
					$('#bigdiv2 .button').unbind('click');
					var phone = String($('option:selected', '#regform-country').attr('data-id'));
					phone = phone.replace("+","");
					var mobile ; 
					 mobile = String($('#regform-phone').val().replace("+",""));
					if(mobile.substr(0,String(phone).length) == phone )
					{
						mobile = '00'+mobile;
					}
					
					
					
					var pUser = {uUname:$('#regform-user').val(),
								 uPassword:$('#regform-pass').val(), 
								 uEmail:$('#regform-email').val(),
								 uMobile:mobile,
								 uFirstName:$('#regform-fname').val(),
								 uMidName:'',
								 uLastName:$('#regform-lname').val(),
								 uCountryID:$('#regform-country').val()
								 };
								 pUser = JSON.stringify(pUser);
								 pUser = JSON.stringify(pUser);
  									
									
								   $.ajax({
										type: 'POST',
										url: url+'CreateNewUser',
										 dataType: 'json',
										 contentType: 'application/json',
										 data: pUser,
										
										
										success: function(msg){
											
											//alert(msg); 
											
											if(msg)
											{
													reglogin();	
											}
										},
										error: function(msg){
											alert('Err:'+ msg)
										}
									});
								 
								
					
				}else{
					$('#bigdiv2 .message').slideDown();
					$('#bigdiv2 .message').html(error);	
				}
			}
			
			
			
			
			
			function reglogin()
				{
					
					
									$('[name="uName"]').val(base64.encode($('#regform-user').val()));
									$('[name="uPass"]').val(base64.encode($('#regform-pass').val()));
									$('[name="uPersistent"]').val(0);
									
									$('#login-data').submit();
				
						/*var logindata = {
									 uName:$('#regform-user').val(),
									 uPass:$('#regform-pass').val(), 
									 uPersistant: true
									 
									 };
						logindata = JSON.stringify(logindata);
						logindata = JSON.stringify(logindata);
										
								  $.ajax({
											type: 'POST',
											url: url+'FastLogin',
											 dataType: 'json',
											 contentType: 'application/json',
											 data: logindata,
											
											
											success: function(msg){
												
												var cred = JSON.parse(msg.FastLoginResult); 
												
												if (cred.IsAuthenticated && cred.IsActivated) {
													window.location = redirect+'master.aspx';
												} else if (cred.IsAuthenticated && !cred.IsActivated) {
													window.location = redirect+'user_activation.aspx';
												} else {
													window.location = redirect+'errorpage.aspx';
												}
											},
											error: function(msg){
												alert('Err:'+ msg)
											}
										});*/
					
								 
				}
			
			
			
			
			
			
			
			
			
			$('#regform-country').change(function(){
					if($('#regform-phone').val().length > 3)
					{
						if($('#regform-phone').val().substr(0,1) == 0)
						{
							$('#regform-phone').val($('option:selected', this).attr('data-id')+ $('#regform-phone').val().substr(1));
						}else{
							$('#regform-phone').val($('option:selected', this).attr('data-id')+ $('#regform-phone').val().substr(3));
						}
						
					}else{
						$('#regform-phone').val($('option:selected', this).attr('data-id'));
					}
					
				});
				
				$('#login-form input').on('keyup', function(e) {
								
								if (e.which == 13) {
									login();
								}
							});
				$('#reg-form input').on('keyup', function(e) {
								
								if (e.which == 13) {
									Registration();
								}
							});
				
				<?php
				if($_GET['prm2'] == 'sign-up'){
				?>
				$(document).ready(function() {
                    $('#bigdiv1').slideUp('fast', function() {
						$('#bigdiv2').slideDown('slow');
						$('.bigarrow').animate({
							'margin-top':'150px'
						});
					});
					
					
					$(this).addClass('redcolor');
					$('#bigtab1').removeClass('redcolor');
                });
				
				<?php	
				}
				?>
   	
   </script>
	
<?php

foot();
?>